package com.tiyende.credit.loop.ui.dialog

import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Color
import android.view.LayoutInflater
import android.view.View
import com.tiyende.credit.loop.R
import com.tiyende.credit.loop.common.CommonDialog
import com.tiyende.credit.loop.databinding.TiyendeDialogAccountDeleteTipsBinding
import com.tiyende.credit.loop.event.TiyendeEventPointType
import com.tiyende.credit.loop.utils.TiyendeImageUtil
import org.json.JSONObject

/**
 * TiyendeCredit
 * @Author wwdeng
 * @CreateTime: 2024/11/21 13:45
 * @Annotation：绑卡删除dialog
 */
class TiyendeAccountDeleteDialog: CommonDialog {
    private lateinit var binding: TiyendeDialogAccountDeleteTipsBinding
    private var mCallback: IDialogCallback? = null

    //事件备注
    private var eventRemark = ""

    constructor(context: Context) : super(context) {}
    constructor(context: Context, callback: IDialogCallback?) : super(context) {
        mCallback = callback
    }

    constructor(context: Context, remark: String,callback: IDialogCallback?) : super(context) {
        mCallback = callback
        eventRemark = remark
    }

    /**
     * 设置点击回调
     */
    fun setOnClick(callback: IDialogCallback){
        this.mCallback = callback
    }

    override fun getTiyendeRootView(): View {
        binding = TiyendeDialogAccountDeleteTipsBinding.inflate(LayoutInflater.from(context))
        return binding.root
    }

    override fun initTiyendeView() {
    }

    override fun initTiyendeListener() {
        setOnClickListener(binding.walletDeleteCancel)
        setOnClickListener(binding.walletDeleteConfirm)
        setOnClickListener(binding.imageClose)//关闭
    }

    override fun loadTiyendeData() {
    }

    override fun onTiyendeViewClick(v: View?) {
        dismiss()
        when(v?.id){
            R.id.walletDeleteCancel -> {
                addEventPointRequestAction(TiyendeEventPointType.CLICK.TIYENDE_CLICK_USER_ACCOUNT_DELETE_TIPS_CANCEL,eventRemark)
            }
            R.id.walletDeleteConfirm -> {
                addEventPointRequestAction(TiyendeEventPointType.CLICK.TIYENDE_CLICK_USER_ACCOUNT_DELETE_TIPS_CONFIRM,eventRemark)
            }
        }
        mCallback?.onClick(v)
    }

    /**
     * 设置需要删除的账户信息
     */
    @SuppressLint("SetTextI18n")
    fun setBindAccountInfo(info: JSONObject){
        binding.walletItem.itemLayout.shapeDrawableBuilder.setSolidColor(Color.parseColor("#FF000000")).intoBackground()
        TiyendeImageUtil.instance?.loadImageUrl(context,binding.walletItem.walletLogo,info.optString("walletLogo"), R.mipmap.tiyende_holder)
        binding.walletItem.walletTitle.text = info.optString("walletDesc")
        binding.walletItem.walletMobile.text = "+" + info.optString("walletMobile")
        binding.walletItem.walletDelete.visibility = View.INVISIBLE
    }

    interface IDialogCallback {
        //按钮点击
        fun onClick(view: View?)
    }

    override fun onStart() {
        super.onStart()
        addEventPointRequestAction(TiyendeEventPointType.DIALOG.TIYENDE_DIALOG_USER_ACCOUNT_DELETE_TIPS_SHOW,eventRemark)
    }

    override fun dismiss() {
        super.dismiss()
        addEventPointRequestAction(TiyendeEventPointType.DIALOG.TIYENDE_DIALOG_USER_ACCOUNT_DELETE_TIPS_DISMISS,eventRemark)
    }
}